package com.wwy.listener;

import com.wwy.LabelPanel;
import com.wwy.SwingArea;
import com.wwy.service.MacDataService;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

/**
 * @Author: wwy
 * @Date: 2020/8/13 12:58
 */
public class MenuActionListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        switch (e.getActionCommand()){
            case "newLabel":
                //新增lable
                SwingArea.getInstance().createLabelDialog();
                break;
            case "newType":
                System.out.println("newType");
                SwingArea.getInstance().createLabelTypeDialog();
                break;
            case "start":
                System.out.println("开始执行");
                MacDataService.status = true;
                break;
            case "close":
                System.out.println("关闭执行");
                MacDataService.status = false;
                break;
            case "clear":
                for (Map.Entry<String, DefaultTableModel> stringDefaultTableModelEntry : LabelPanel.modelMap.entrySet()) {
                    DefaultTableModel tableModel = stringDefaultTableModelEntry.getValue();
                    for (int i = tableModel.getRowCount()-1; i >=0; i--) {
                        tableModel.removeRow(i);
                    }

                }
                //清理屏幕
                System.out.println("清理屏幕执行");
                break;
            case "rssi":
                System.out.println("rssi设置");
                SwingArea.getInstance().createRssiDialog();
                break;
            case "filtrationTime":
                //过滤时间设置
                System.out.println("过滤时间设置");
                SwingArea.getInstance().createFiltrationTimeDialog();
                break;
        }
    }
}
